﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Http;
using System.Web.Routing;

namespace YiYiTong.Rocket.Api
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            //配置log4
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/Web.config")));

            GlobalConfiguration.Configure(WebApiConfig.Register);
            RegService();
        }

        /// <summary>
        /// 通过遍历所有的类获取是否是Service
        /// </summary>
        public void RegService()
        {
            Assembly _Assembyle = Assembly.GetExecutingAssembly();
            Type[] _TypeList = _Assembyle.GetTypes();

            for (int i = 0; i != _TypeList.Length; i++)
            {
                if (_TypeList[i].Name.EndsWith("Service") && _TypeList[i].Name != "ApiService")
                {
                    Activator.CreateInstance(_Assembyle.FullName, _TypeList[i].FullName);
                }
            }
        }
    }
}
